//
//  LKBackCommissionViewController.m
//  Mideleague_Agent
//
//  Created by Zhiwang on 2020/9/14.
//  Copyright © 2020 Zhiwang. All rights reserved.
//

#import "LKBackCommissionViewController.h"
#import "LKTreeBenefitViewController.h"
#import "LKPickeCustomView.h"
#import "LKBenefitModel.h"
#import "SegmentTapView.h"
#import "FlipTableView.h"
#import "LKBackCommissionSonViewController.h"
#import "LKDirectShopViewController.h"


@interface LKBackCommissionViewController ()<FlipTableViewDelegate,SegmentTapViewDelegate>


@property (nonatomic, strong)SegmentTapView *segment;
@property (nonatomic, strong)FlipTableView *flipView;

@property(nonatomic,strong)LKPickeCustomView *sorcepickerView;
@property(nonatomic,strong)NSMutableArray *dateArray;


@property (weak, nonatomic) IBOutlet UILabel *yearSumLabel;
@property (weak, nonatomic) IBOutlet UILabel *yearAgentLabel;
@property (weak, nonatomic) IBOutlet UILabel *yearShopLabel;
@property(nonatomic,strong)LKBenefitModel *yeaderBenefitModel;
@property(nonatomic,strong)LKBenefitModel *chooseBenefitModel;
@property (weak, nonatomic) IBOutlet UIImageView *headerBgImageView;

@end

@implementation LKBackCommissionViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"聚合费率返佣";
    [self setNavgationRightBtn];
    [self getYearBenefitData];
    [self createContainerVC];
    [self.view sendSubviewToBack:self.headerBgImageView];
    // Do any additional setup after loading the view from its nib.
}
-(NSMutableArray *)dateArray{
    if (_dateArray == nil) {
        _dateArray = [[NSMutableArray alloc] init];
    }
    return _dateArray;
}
/**
 设置返回按钮样式
 */
-(void)setNavgationRightBtn{
    WS(weakSelf)
    LKBaseButton *rightBtn = [LKBaseButton buttonWithFrame:CGRectMake(0, 0, 64, 24) type:UIButtonTypeCustom title:@"下级收益" titleColor:COLOR_HEX(0xF86747) layercorne:15 font:[UIFont fontWithName:@"PingFangSC-Regular" size: 12] backgroudColor:[UIColor clearColor] AndActionBlock:^(UIButton * _Nonnull btn) {
//        LKDirectShopViewController *vc = [[LKDirectShopViewController alloc] init];
//        vc.hidesBottomBarWhenPushed = YES;
//        [weakSelf.navigationController pushViewController:vc animated:YES];
        LKTreeBenefitViewController *vc = [[LKTreeBenefitViewController alloc] init];
        vc.isShowCheck = NO;
        vc.isShowTimeChoose = YES;
//        vc.hidesBottomBarWhenPushed = YES;
        [weakSelf.navigationController pushViewController:vc animated:YES];
    }];
    rightBtn.layer.borderColor = COLOR_HEX(0xF86747).CGColor;
    rightBtn.layer.borderWidth = 1;
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
}
-(void)createContainerVC{
        self.segment = [[SegmentTapView alloc] initWithFrame:CGRectMake(0,NAVIGATION_BAR_HEIGHT + 160 + 10, WIDTH, 40) withDataArray:[NSArray arrayWithObjects:@"日收益",@"月收益",@"年收益", nil] withFont:14];
        self.segment.delegate = self;
        self.segment.lineColor = yellowDefaultColor;
        self.segment.titleFont = 14;
        self.segment.textNomalColor = COLOR_HEX(0x333333);
        self.segment.textSelectedColor = yellowDefaultColor;
        [self.view addSubview:self.segment];
        LKBackCommissionSonViewController *list1 = [[LKBackCommissionSonViewController alloc] init];
         list1.timeType = LKBackCommissionTypeDay;
        LKBackCommissionSonViewController *list2 = [[LKBackCommissionSonViewController alloc] init];
         list2.timeType = LKBackCommissionTypeMonth;
        LKBackCommissionSonViewController *list3 = [[LKBackCommissionSonViewController alloc] init];
         list3.timeType = LKBackCommissionTypeYear;
        self.flipView = [[FlipTableView alloc] initWithFrame:CGRectMake(0, NAVIGATION_BAR_HEIGHT + 220, WIDTH, HEIGHT - (NAVIGATION_BAR_HEIGHT + 360)) withArray:@[list1,list2,list3]];
        self.flipView.delegate = self;
        [self.view addSubview:self.flipView];
}
#pragma mark -------- select Index
-(void)selectedIndex:(NSInteger)index
{
    [self.flipView selectIndex:index];
}

-(void)scrollChangeToIndex:(NSInteger)index
{
    [self.segment selectIndex:index];
}

-(void)getYearBenefitData{
    [SVProgressHUD show];
    NSString *currentTime = [NSString getCurrentTime];
    NSDictionary *param = @{@"token":[LKUserInforTool account].token,@"uid":[LKUserInforTool account].uid,@"year":[[currentTime componentsSeparatedByString:@"-"] firstObject]};
    [[LKNetDataManager defaultManager] sendRequestMethod:HTTPMethodPOST serverUrl:ServerlUrl apiPath:MyBenefitUrl header:[LKUserInforTool account].token parameters:param progress:^(NSProgress * _Nullable progress) {
        
    } success:^(BOOL isSuccess, id  _Nullable responseObject) {
        [SVProgressHUD dismiss];
        if ([responseObject[@"code"] isEqualToString:@"success"]) {
            self.yeaderBenefitModel = [LKBenefitModel modelWithDictionary:responseObject];
            self.yearShopLabel.text = self.yeaderBenefitModel.getmisson;
            self.yearAgentLabel.text = self.yeaderBenefitModel.merchant_data;
            self.yearSumLabel.text = self.yeaderBenefitModel.sum;
        }else{
            [SVProgressHUD showInfoWithStatus:responseObject[@"msg"]];
        }

    } failure:^(NSString * _Nullable errorMessage) {
        [SVProgressHUD dismiss];
    }];
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */



@end
